Apache mod_rewrite to filter HTTP POST requests - example

chris (2006-09-29 14:51:49)
4298 views
0 replies
This is a trick for filtering unwanted HTTP requests to your webserver - Let's say you only want to handle HEAD and GET requests - that means that POST, TRACE, etc will be blocked. This is how you would apply that using mod_rewrite in your httpd.conf:
RewriteEngine on
RewriteCond %{THE_REQUEST} !^(GET|HEAD)
RewriteRule ^ / [R=301]

Note the use of the 'R' flag - this allows you to specify the response code passed back. If no R value is set, Apache will default to a 302. In this case we're using a 301.


christo
comment